import { Application } from 'egg';
import {
  indexRule,
  createRule,
  updateRule,
  destroyRule,
} from '../validate/sms/coupon';



/**
 * 小程序路由
 */
export default (app: Application) => {
  const { auth } = app.middleware;
  const { jwt } = app;

  return {
    'marketing.coupon.list': {
      method: 'GET',
      path: '/api/sms/coupon/list',
      options: {
        tags: [ '/coupon/list' ],
        description: '优惠券列表',
        handler: app.controller.marketing.coupon.list,
        middlewares: [jwt, auth('marketing.coupon')],
        validate: indexRule,
      },
    },
    'marketing.coupon.create': {
      method: 'POST',
      path: '/api/sms/coupon/list',
      options: {
        tags: ['coupon/create'],
        description: '创建优惠券',
        handler: app.controller.marketing.coupon.create,
        middlewares: [jwt, auth('marketing.coupon.create')],
        validate: createRule,
      },
    },
    'marketing.coupon.update': {
      method: 'PUT',
      path: '/api/sms/coupon/list/:id',
      options: {
        tags: ['coupon/update'],
        description: '更新活动',
        handler: app.controller.marketing.coupon.update,
        middlewares: [jwt, auth('marketing.coupon.update')],
        validate: updateRule,
      },
    },
    'marketing.coupon.destroy': {
      method: 'DELETE',
      path: '/api/sms/coupon/list/:id',
      options: {
        tags: ['coupon/delete'],
        description: '删除活动',
        handler: app.controller.marketing.coupon.destroy,
        middlewares: [jwt, auth('marketing.coupon.destroy')],
        validate: destroyRule,
      },
    },
  };

};
